package edu.java.texbooks.scjp.collections.test05.converting.list.to.array;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Test {
	public static void main(String[] args) {
		// test01();

		test02();

		// some note for arrays --> they are objects
		// test03();
	}

	public static void test01() {
		List<Integer> listIntegers = new ArrayList<Integer>();
		listIntegers.add(1);
		listIntegers.add(4);
		listIntegers.add(8);

		System.out.println("\n" + "list of integers: " + listIntegers);

		// convert List to array of "Object" type
		Object[] objectArray = listIntegers.toArray();
		System.out.println("\n" + "ObjectArray: "
				+ Arrays.toString(objectArray));

		// convert List to array of "Integer" type
		Integer[] integerArray = new Integer[listIntegers.size()];
		integerArray = listIntegers.toArray(integerArray);

		System.out.println("\n" + "IntegerArray: "
				+ Arrays.toString(integerArray));

	}

	public static void test02() {
		List<Integer> listIntegers = new ArrayList<Integer>();
		listIntegers.add(1);
		listIntegers.add(3);
		listIntegers.add(10);
		listIntegers.add(2);
		listIntegers.add(8);

		System.out.println("\n" + "list of integers: " + listIntegers);

		// convert List to array of "Integer" type
		Integer[] integerArray = new Integer[1];
		integerArray = listIntegers.toArray(integerArray);

		// quick way to get array --> on 1 line
		Integer[] specArray = listIntegers.toArray(new Integer[1]);

		System.out.println("\n" + "IntegerArray: "
				+ Arrays.toString(integerArray));

		System.out.println("\n" + "SpecArray: " + Arrays.toString(specArray));

	}

	public static void test03() {
		int[] myInts = new int[3];
		int[] yourInts = { 1, 2, 3, 4, 5, 6 };
		myInts = yourInts;
		System.out.println(Arrays.toString(myInts));
	}
}
